// https://leetcode.cn/problems/validate-binary-search-tree/

// 给你一个二叉树的根节点 root ，判断其是否是一个有效的二叉搜索树。

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */


#include <iostream>
#include <vector>


using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;

    TreeNode() : val(0), left(nullptr), right(nullptr) {}

    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}

    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};


class Solution {
public:
    bool flag = true;
    long long prev = LLONG_MIN;
    bool isValidBST(TreeNode *root) {
        if(root->left == nullptr && root->right == nullptr) return true;
        show(root);
        return flag;
    }

    // 中序遍历
    void show(TreeNode *root){
        if(root){
            show(root->left);
            if(root->val > prev){
                prev = root->val;
            }else{
                flag = false;
                return;
            }
            show(root->right);
        }
    }

};


int main() {
    Solution so;

    return 0;
}
